package com.ynny.servic;

import com.ynny.entity.User;
import com.ynny.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
     UserMapper userMapper;
    @Override
    public boolean login(String number, String password) {

        //1.检查用户名是否存在
        User repeatUser = userMapper.selectUserById(Integer.parseInt(number));
        if (repeatUser != null){

            return false;
        }
        //2.登录
        User user = userMapper.selectUserById(Integer.parseInt(number));
        if (user != null && user.getPassword().equals(password)){
            return true;
        }
        return false;
    }

    @Override
    public boolean register(String number, String password) {
        //1.检查用户名是否存在
        User repeatUser = userMapper.selectUserById(Integer.parseInt(number));
        if (repeatUser != null){
            return false;
        }
        //2.注册
        User user = new User();
        user.setNumber(Integer.parseInt(number));
        user.setPassword(password);
        userMapper.insertUser(user);
        return true;
    }
}
